<?php

namespace App\Http\Controllers;

use App\Http\Controllers\BaseController;
use App\Services\MeetOrderService;
use Illuminate\Http\Request;

class MeetOrderController extends BaseController
{
    public function __construct(MeetOrderService $meetOrderService)
    {
        $this->middleware('check.login')->except('index');

        $this->meetOrderService = $meetOrderService;
    }

    public function show(Request $request)
    {
        $param = $this->validationParameter([
            'venue_id|场馆id' => 'noRequire',
            'page|页码' => 'noRequire|number|default:1',
            'per_page|显示数量' => 'noRequire|number|default:30',
        ]);
        $param['user_id'] = $request->user('api')->user_id ?? null;

        $result = $this->meetOrderService->getList($param);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'venue_id|场馆id' => 'require',
            'meet_hour_id|场馆小时id' => 'require',
            'meet_person_id|预约人id' => 'require|array',
        ]);
        $param['add_uid'] = $request->user('api')->user_id ?? null;

        $result = $this->meetOrderService->add($param);

        return $this->response->success($result);
    }

    public function cancel(Request $request)
    {
        $param = $this->validationParameter([
            'id|预约记录id' => 'require',
        ]);
        $this->meetOrderService->cancel($param);

        return $this->response->success();

    }

}
